package com.yxx.controller.user;

import com.yxx.medicinecommon.constant.StatusConstant;
import com.yxx.medicinecommon.result.ResponseResult;
import com.yxx.medicinepojo.entity.SetMedicine;
import com.yxx.medicinepojo.vo.ChineseWesternMedicineDetailListVO;
import com.yxx.service.SetMedicineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yuxiangxun
 * @date 2024/9/26
 * @apiNote
 */
@RequestMapping("/user/setmedicine")
@RestController("userSetMedicineController")
@Slf4j
@Api(tags = "小程序端 组合药")
public class SetMedicineController {
    @Autowired
    private SetMedicineService setMedicineService;

    /**
     * 条件查询组合药信息
     * @param medicinecategoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("条件查询组合药信息")
    @Cacheable(cacheNames = "setmedicineCache", key = "#medicinecategoryId",cacheManager = "cacheManager_config") //key:  UsersetmedicineCache::100
    public ResponseResult<List<SetMedicine>> list(Long medicinecategoryId){
        SetMedicine setMedicine = SetMedicine.builder()
                .status(StatusConstant.ENABLE)
                .categoryId(medicinecategoryId)
                .build();

        List<SetMedicine> setMedicineList = setMedicineService.list(setMedicine);
        return ResponseResult.success(setMedicineList);
    }

    /**
     * 根据组合药id查询中西药列表信息
     * @param id
     * @return
     */
    @GetMapping("/chinesewesternmedicine/{id}")
    @ApiOperation("根据组合药id查询中西药列表信息")
    public ResponseResult<List<ChineseWesternMedicineDetailListVO>> chineseWesternMedicineDetailList(@PathVariable("id") Long id){
        List<ChineseWesternMedicineDetailListVO> chineseWesternMedicineDetailListVOList = setMedicineService.chineseWesternMedicineDetailListById(id);
        return ResponseResult.success(chineseWesternMedicineDetailListVOList);
    }
}
